package genedit.controller.interfaceActions;

import genedit.gui.GMainFrame;
import genedit.model.Workspace;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

/**
 * Akcija zatvara sve projekte u stablu hijerarhije i čisti stablo tako da
 * ostane samo korenski čvor. Pre uklanjanja iz stabla, svi dokumenti bivaju
 * sačuvani.
 * 
 * @see GSaveAllA
 * @author Nikola
 * @version 1.0 10/11/13
 */
public class GCloseAllA extends AbstractAction {
	private static final long serialVersionUID = 1L;

	private static GCloseAllA instance;

	public static GCloseAllA getInstance() {
		if (instance == null)
			instance = new GCloseAllA();
		return instance;
	}

	public GCloseAllA() {
		putValue(NAME, "Close All");
		putValue(SHORT_DESCRIPTION, "Close All");
		putValue(SMALL_ICON, new ImageIcon("resources/icons/close.png"));
		putValue(MNEMONIC_KEY, KeyEvent.VK_L);
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control F4"));
	}

	/**
	 * Akcija čuva sve dokumente, zatim zatvara sve otvorene dijagrame ukoliko
	 * ih ima i na kraju prazni stablo hijerarhije.
	 */
	public void actionPerformed(ActionEvent arg0) {
		GSaveAllA.getInstance().actionPerformed(arg0);
		GMainFrame.getInstance().removeAllGraphDocumentView();
		Workspace.getInstance().removeAllProjects();
	}

}